const initialState = {
  list: [
    { id: 1, task: "学习React", isDone: false },
    { id: 2, task: "学习Vue", isDone: true },
    { id: 3, task: "学习TS", isDone: true },
  ],
  type: "all",
};

const todoReducer = (state = initialState, { type, payload }) => {
  console.warn("type, payload  ----->  ", type, payload);
  switch (type) {
    case "delById":
      return {
        ...state,
        list: state.list.filter((item) => item.id !== payload),
      };

    case "updateById":
      return {
        ...state,
        list: state.list.map((item) => ({
          ...item,
          isDone: item.id === payload ? !item.isDone : item.isDone,
        })),
      };

    case "updateType":
      return { ...state, type: payload };

    default:
      return state;
  }
};

export default todoReducer;
